package com.test.cordova.util;

import android.content.Context;
import android.content.SharedPreferences;

public class SharedPreferencesUtil {

    private static final String spFileName = "stealthdemo";

    public static Boolean getBoolean(Context context, String strKey, Boolean strDefault) {//strDefault	boolean: Value to return if this preference does not exist.
        SharedPreferences setPreferences = context.getSharedPreferences(spFileName, Context.MODE_WORLD_READABLE | Context.MODE_MULTI_PROCESS);
        Boolean result = setPreferences.getBoolean(strKey, strDefault);
        return result;
    }

    public static void putBoolean(Context context, String strKey, Boolean strData) {
        SharedPreferences activityPreferences = context.getSharedPreferences(spFileName, Context.MODE_WORLD_READABLE | Context.MODE_MULTI_PROCESS);
        SharedPreferences.Editor editor = activityPreferences.edit();
        editor.putBoolean(strKey, strData);
        editor.commit();
    }

    public static String getString(Context context, String strKey, String strDefault) {//strDefault	boolean: Value to return if this preference does not exist.
        SharedPreferences setPreferences = context.getSharedPreferences(spFileName, Context.MODE_WORLD_READABLE | Context.MODE_MULTI_PROCESS);
        String result = setPreferences.getString(strKey, strDefault);
        return result;
    }

    public static void putString(Context context, String strKey, String strData) {
        SharedPreferences activityPreferences = context.getSharedPreferences(spFileName, Context.MODE_WORLD_READABLE | Context.MODE_MULTI_PROCESS);
        SharedPreferences.Editor editor = activityPreferences.edit();
        editor.putString(strKey, strData);
        editor.commit();
    }

    public static int getInt(Context context, String strKey, int strDefault) {//strDefault	boolean: Value to return if this preference does not exist.
        SharedPreferences setPreferences = context.getSharedPreferences(spFileName, Context.MODE_WORLD_READABLE | Context.MODE_MULTI_PROCESS);
        int result = setPreferences.getInt(strKey, strDefault);
        return result;
    }

    public static void putInt(Context context, String strKey, int strData) {
        SharedPreferences activityPreferences = context.getSharedPreferences(spFileName, Context.MODE_WORLD_READABLE | Context.MODE_MULTI_PROCESS);
        SharedPreferences.Editor editor = activityPreferences.edit();
        editor.putInt(strKey, strData);
        editor.commit();
    }
    public static long getLong(Context context, String strKey, long strDefault) {//strDefault	boolean: Value to return if this preference does not exist.
        SharedPreferences setPreferences = context.getSharedPreferences(spFileName, Context.MODE_WORLD_READABLE | Context.MODE_MULTI_PROCESS);
        long result = setPreferences.getLong(strKey, strDefault);
        return result;
    }

    public static void putLong(Context context, String strKey, long strData) {
        SharedPreferences activityPreferences = context.getSharedPreferences(spFileName, Context.MODE_WORLD_READABLE | Context.MODE_MULTI_PROCESS);
        SharedPreferences.Editor editor = activityPreferences.edit();
        editor.putLong(strKey, strData);
        editor.commit();
    }

    /**
     * 是否存在 strkey
     * @param context
     * @param strKey
     */
    public static boolean contains(Context context, String strKey) {
        SharedPreferences activityPreferences = context.getSharedPreferences(spFileName, Context.MODE_WORLD_READABLE | Context.MODE_MULTI_PROCESS);
        return activityPreferences.contains(strKey);
    }

}
